/*本模块功能:教师管理(管理员)
 编写者:朱光曜
 编写时间:2017.11.03
 editor:yxj 20180510*/
$(function() {
    function formatDate(now) {//处理时间戳
        var year = now.getFullYear();
        var month = now.getMonth() + 1;
        var date = now.getDate();
        var hour = now.getHours();
        var minute = now.getMinutes();
        if(month<10){month="0"+month;}
        if(date<10){date="0"+date;}
        if(hour<10){hour="0"+hour;}
        if(minute<10){minute="0"+minute;}
        return year + "-" + month + "-" + date + "   " + hour + ":" + minute;
    }
    var string1 = '<tr>' +
        '<th class="col-lg-2"></th>' +
        '<th class="col-lg-5">院系</th>' +
        '<th class="col-lg-5">专业</th>' +
        '<th class="col-lg-5">工号</th>' +
        '<th class="col-lg-6">姓名</th>' +
        '<th class="col-lg-4">性别</th>' +
        '<th class="col-lg-5">联系方式</th>' +
         '<th class="col-lg-5">过期时间</th>' +
        /*'<th class="col-lg-6">操作</th>' +*/
        '</tr>';
    var confirm1 = new Confirm;
    var confirm2= new Confirm;
    var confirm3= new Confirm;
    var Alert1 = new Alert;
    var Alert2 = new Alert;


    function myMessage(message) { //添加教师

        var departmentStr = '<option value="1">请选择</option>';
        var roleStr = '<option value="1">请选择</option>';
        for(key in message.departMentList) {
            departmentStr += '<option value="1" departmentId="' + message.departMentList[key].departmentId + '">' + message.departMentList[key].departmentName + '</option>';
        }

        return '<div id="appendUser">' +
            '<div class="fl inputRight"><label for="Name">姓&ensp;&ensp;&ensp;&ensp;名:&ensp;</label><input autocomplete="off" type="text" id="name" class="publicText" placeholder="请输入姓名"/></div>' +
            '<div class="fl sex"><span style="margin-right:0;">性&ensp;&ensp;&ensp;&ensp;别:&ensp;</span>' +
            '<input type="radio" checked="checked" name="sex" id="man" value="" /><label for="man" class="checked">男</label>' +
            '<input type="radio" name="sex" id="woman" value="" /><label for="woman">女</label>' +
            '</div>' +
            '<div class="fl inputRight"><label for="departName">联系方式:&ensp;</label><input type="text" autocomplete="off" id="phone" class="publicText" placeholder="请输入电话号码"/></div>' +
            '<div class="fr inputRight"><label for="departName">工&ensp;&ensp;&ensp;&ensp;号:&ensp;</label><input autocomplete="off" placeholder="请输入工号" type="text" id="workNum" class="publicText" /></div>' +

            '<div class="fl inputRight"><label for="departNames">院&ensp;&ensp;&ensp;&ensp;系:&ensp;</label>' +
            '<select id="department" class="publicSelect" />' +
            departmentStr +
            '</select>' +
            '</div>' +

            '<div class="fr inputRight"><label for="departNames">专&ensp;&ensp;&ensp;&ensp;业:&ensp;</label>' +
            '<select id="major" class="publicSelect" />' +
            roleStr +
            '</select>' +
            '</div>' +
            '<div class="fl inputRight"><label for="Name">密&ensp;&ensp;&ensp;&ensp;码:&ensp;</label><input autocomplete="off" type="text" id="password" class="publicText" placeholder="请输入密码"/></div>' +
            '<div class="fr inputRight"><label for="Name">确认密码:&ensp;</label><input type="text" autocomplete="off" id="passwordTrue" class="publicText" placeholder="请输入确认密码"/></div>' +
            '<div class="fl inputRight"><label for="departNames">过期时间:&ensp;</label>' +
            // '<select id="overdueTime" class="publicSelect" />' +
            // '<option overdueTime="1">1</option>'+
            // '<option overdueTime="2">2</option>'++
            // '<option overdueTime="3">3</option>'+
            // '<option overdueTime="4">4</option>'+
            // '<option overdueTime="5">5</option>'+
            // '<option overdueTime="6">6</option>'+
            // '<option overdueTime="7">7</option>'+
            // '<option overdueTime="8">8</option>'+
            // '<option overdueTime="9">9</option>'+
            // '<option overdueTime="10">10</option>'+
            // '</select>' +
            '<input type="number" id="overdueTime" class="publicSelect" maxlength="3" /> 天'+
            '</div>' +
            '<div class="clear"></div>' +
            '</div>';
    }

    function setTeacher(data, sexThis) { //教师详情

        if(sexThis == "男") {
            var sexList = '<input type="radio" checked="checked" name="sex" id="man" value=""/><label for="man" class="checked">男</label> <input type="radio" name="sex" id="woman" value=""/><label for="woman">女</label>';
        }
        if(sexThis == "女") {
            var sexList = '<input type="radio"  name="sex" id="man" value=""/><label for="man" >男</label> <input type="radio" checked="checked"  name="sex" id="woman" value=""/><label for="woman" class="checked">女</label>';
        }
        return '<div id="appendUser">' +
            '<div class="fl inputRight"><label for="teacherName" class="fl">教师姓名:&ensp;</label><input autocomplete="off" type="text" id="teacherName" class="publicText" value="' + data.memberList[0].userName + '" /></div>' +
            '<div class="fl sex"><span>性&ensp;&ensp;&ensp;&ensp;别:&ensp;</span>' +
            sexList +
            '</div>' +
            '<div class="fl inputRight"><label for="phone">联系方式:&ensp;</label><input type="text" autocomplete="off" id="phone" placeholder="请输入联系方式" class="publicText"   value="' + data.memberList[0].telephoneNum + '" /></div>' +
            '<div class="fr inputRight"><label  class="fl">工&ensp;&ensp;&ensp;&ensp;号:&ensp;</label><div class="fl" id="workId" title="' + data.memberList[0].stuorteaId + '">' + data.memberList[0].stuorteaId + '</div></div>' +
            '<div class="fl inputRight"><label  class="fl">院&ensp;&ensp;&ensp;&ensp;系:&ensp;</label>' +
            '<div class="fl" title="' + data.memberList[0].departmentName + '">' + data.memberList[0].departmentName + '</div>' +
            '</div>' +
            '<div class="fr inputRight"><label for="departNames" class="fl">专&ensp;&ensp;&ensp;&ensp;业:&ensp;</label>' +
            '<div class="fl" title="' + data.memberList[0].professionName + '">' + data.memberList[0].professionName + '</div>' +
            '</div>' +
            '<div class="fl inputRight last"><label for="departNames" class="fl">教师简介:&ensp;</label>' +
            '<textarea id="teacherIntroduction" name="" rows="" cols="" class="fl">' + data.memberList[0].userContect + '</textarea>' +
            '</div>' +
            '<div class="clear"></div>' +
            '</div>';
    }
    
    function tabelModel(data) {//列表内容
        var sex = "";
        var time = new Date(data.memberList[key].overdueTime);
        return '<tr data-num="0">' +
            '<td class="col-lg-2"><input datavalue="' + data.memberList[key].stuorteaId +' " name="selecteds" type="radio" class="oneCheck" datavalueTwo="' + data.memberList[key].userName +' " stuorteaId="' + data.memberList[key].stuorteaId + '"/></td>' +
            '<td class="col-lg-3"  title="' + data.memberList[key].departmentName + '">' + data.memberList[key].departmentName + '</td>' +
            '<td class="col-lg-3"  title="' + data.memberList[key].professionName + '">' + data.memberList[key].professionName + '</td>' +
            '<td class="col-lg-6"  title="' + data.memberList[key].stuorteaId + '">' + data.memberList[key].stuorteaId + '</td>' +
            '<td class="col-lg-5" title="' + data.memberList[key].userName + '">' + data.memberList[key].userName + '</td>' +
            '<td class="col-lg-2 sexName">' + data.memberList[key].sexName + '</td>' +
            '<td class="col-lg-3"  title="' + data.memberList[key].telephoneNum + '">' + data.memberList[key].telephoneNum + '</td>' +
            '<td class="col-lg-3"  title="' + formatDate(time) + '">' + formatDate(time) + '</td>' +
            '<td class="col-lg-4">' +
            '<a href="javascript:;" class="set">修改</a>' +
            '<a class="initialization" href="javascript:;"  stuorteaId="' + data.memberList[key].stuorteaId + '">初始化密码</a>' +
            '</td>' +
            '</tr>';
    }
    var loading1 = new Loading();//监控全局ajax添加loading
    loading1.init();
    $(document).ajaxSend(function(){
        loading1.show();

    });
    $(document).ajaxStop(function(){
        loading1.hide();

    });
    document.addEventListener('DOMSubtreeModified',function(e){//去除空格
        $(".publicText").attr("maxlength","20");
        $("textarea").attr("maxlength","200");

        $.map($(".publicText"),function (opt) {//长度限制
            maxLengthLimit.init(opt);
        });
        $.map($("textarea"),function (opt) {//长度限制
            maxLengthLimit.init(opt);
        });
        $(".publicText").bind('input propertychange',function(){

            var regy = /\s/g;
            if(regy.test($(this).val())){
                $(this).val($(this).val().replace(/\s|\xA0/g,"")) ;
            }
        });
        $("textarea").bind('input propertychange',function(){//textarea去除空格

            var regy = /\s/g;
            if(regy.test($(this).val())){
                $(this).val($(this).val().replace(/\s|\xA0/g,"")) ;
            }
        });
    });
    var nowData = 1;
    var index = {
        init: function() {
            this.bind();
        },
        bind: function() {
            var self = this;
            this.data_content = {}; //搜索集
            this.tab_content = {}; //列表集

            this.parameter = {
                "pageNow": 1,
                "pageSize": 10,
                "roleMark": 2,
                "roleId":2,
                "selecetRoleId":2
            };

            this.postData(this.parameter, nowData);
            $(document).off("click", ".alert_img").on("click", ".alert_img", function() {//点击删除id
                $(".alert").removeAttr("id");
            });
            $(".loadTeacher").off("click").click(function(){//点击下载
                window.location.href="xlsStandard/teacher.xls";
            });


            $(".deleteTeacher").off("click").on("click", function() {

                var val = $('input[name="selecteds"]:checked').attr("datavalue");
                var name = $('input[name="selecteds"]:checked').attr("datavalueTwo");
                if(val==undefined){
                    Alert1.contenthead = "提示";
                    Alert1.content = "请选择教师";
                    Alert1.success = function() {};
                    Alert1.init();
                    Alert1.show();
                    return false;
                }
                window.location.href="overdueClassEdit?stuorteaId="+val+"&userName="+name;
            });
            $(".addTeacher").off("click").click(function() { //添加教师
                var par = {
                    "pageType": 1
                };
                var $_self = self;
                $.ajax({
                    type: "post",
                    url: "skipAddMember",
                    async: true,
                    data: {
                        "jsonStr": JSON.stringify(par)
                    },

                    success: function(msg) {

                        var msgNew = JSON.parse(msg);

                        var method = myMessage(msgNew);
                        var $self = $_self;
                        var sub = function() {
                            var stuorteaId = $("#workNum").val();
                            var userName = $("#name").val();
                            var telephoneNum = $("#phone").val();
                            var departmentId = $("#department option:selected").attr("departmentId");
                            var professionId = $("#major option:selected").attr("professionid");
                            var aWord = $("#password").val();
                            var bWord = $("#passwordTrue").val();
                            var n = /^[1-9]\d*$|^0$/;

                            if(verification.specialCode(stuorteaId) !== true) {
                                self.alert1("不能输入特殊字符(@/'\"#$%&^*)","fail");
                            }else if(verification.specialCode(userName) !== true) {
                                self.alert1("不能输入特殊字符(@/'\"#$%&^*)","fail");
                            }else if(verification.specialCode(telephoneNum) !== true) {
                                self.alert1("不能输入特殊字符(@/'\"#$%&^*)","fail");
                            }else if(verification.specialCode(aWord) !== true) {
                                self.alert1("不能输入特殊字符(@/'\"#$%&^*)","fail");
                            }else if(verification.specialCode(bWord) !== true) {
                                self.alert1("不能输入特殊字符(@/'\"#$%&^*)","fail");
                            }else if(userName == "") {
                                Alert2.content = "请输入姓名";
                                Alert2.success=function(){
                                    Alert1.show();
                                };
                                Alert2.init();
                                $(".alert").css("width", "640px");
                                Alert2.show();

                            }  else if(stuorteaId.length == 0) {
                                Alert2.content = "请输入工号";
                                Alert2.success=function(){
                                    Alert1.show();
                                };
                                Alert2.init();
                                $(".alert").css("width", "640px");
                                Alert2.show();
                            } else if(verification.stuorTeaIdcode(stuorteaId) !== true) {
                                Alert2.content = verification.stuorTeaIdcode(stuorteaId);
                                Alert2.success=function(){
                                    Alert1.show();
                                };
                                Alert2.init();
                                $(".alert" ).css("width", "640px");
                                Alert2.show();
                            }else   if(departmentId == null) {

                                Alert2.content = "请选择院系";
                                Alert2.success=function(){
                                    Alert1.show();
                                };
                                Alert2.init();
                                $(".alert").css("width", "640px");
                                Alert2.show();
                            } else if(professionId == null) {
                                Alert2.content = "请选择专业";
                                Alert2.success=function(){
                                    Alert1.show();
                                };
                                Alert2.init();
                                $(".alert").css("width", "640px");
                                Alert2.show();
                            } else if(aWord == "") {
                                Alert2.content = "请输入密码";
                                Alert2.success=function(){
                                    Alert1.show();
                                };
                                Alert2.init();
                                $(".alert").css("width", "640px");
                                Alert2.show();
                            } else if(/^[\u4e00-\u9fa5]+$/gi.test(aWord)) {
                                self.alert1("请输入数字和英文组成的密码","fail");
                            }else if(bWord == "") {
                                Alert2.content = "请输入确认密码";
                                Alert2.success=function(){
                                    Alert1.show();
                                };
                                Alert2.init();
                                $(".alert").css("width", "640px");
                                Alert2.show();
                            } else if(/^[\u4e00-\u9fa5]+$/gi.test(bWord)) {
                                self.alert1("请输入数字和英文组成的密码","fail");
                            }else if(aWord !== bWord) {
                                Alert2.content = "请输入相同密码";
                                Alert2.success=function(){
                                    Alert1.show();
                                };
                                Alert2.init();
                                $(".alert").css("width", "640px");
                                Alert2.show();
                            } else {

                                if($(".sex .checked").html() == "男") {
                                    var userSex = 'm';
                                } else {
                                    var userSex = 'f';
                                }
                                var overdueTime = $("#overdueTime").val();
                                if(overdueTime.length >3) {
                                    Alert2.content = "过期时间输入不正确";
                                    Alert2.success = function () {
                                        Alert1.show();
                                    };
                                    Alert2.init();
                                    $(".alert").css("width", "640px");
                                    Alert2.show();
                                    return false;
                                }
                                var parameter = {
                                    "classId": 0,
                                    "telephoneNum": telephoneNum,
                                    "userName": userName,
                                    "userSex": userSex,
                                    "stuorteaId": stuorteaId,
                                    "depId": 0,
                                    "roleId": 2,
                                    "departmentId": departmentId,
                                    "headIcon": "",
                                    "imageUrl": "",
                                    "professionId": professionId,
                                    "password": aWord,
                                    "userContect": "",
                                    "overdueTime":overdueTime

                                };

                                $.ajax({
                                    type: "post",
                                    url: "addMemberExpiryTime",
                                    async: true,
                                    data: {
                                        "jsonStr": JSON.stringify(parameter)
                                    },

                                    success: function(msg) {

                                        var msgNew = JSON.parse(msg);
                                        var self = $self;
                                        if(msgNew.result == "success") {
                                            self.alerty("提交成功");
                                        } else {
                                            //self.alert1(msgNew.errorMsg);
                                            if(msgNew.errorMsg){
                                                self.alertA(msgNew.errorMsg);
                                            }else{
                                                self.alertA("提交失败");
                                            }

                                        }

                                    },
                                    error: function(data, status, xhr) {
                                        var json = JSON.stringify({
                                            "pageName": "error"
                                        });
                                        window.location.href = "skipPage?jsonStr=" + json;

                                    }
                                });
                            }
                        };

                        self.addUser("添加教师", method, sub);

                    },
                    error: function(data, status, xhr) {
                        var json = JSON.stringify({
                            "pageName": "error"
                        });
                        window.location.href = "skipPage?jsonStr=" + json;

                    }
                });

            });


            $(".initTeacher").off("click").click(function() {//点击导入
                $("#Popup .pop_main").html('<div class="pop_main_main"> <label class="form-group" for="teacherMessage"> 班级ID：<input type="text" name="classId" id="classId" value=0> 文件类型：<input type="text" name="type" id="type" value=2> <input type="file" name="file" id="teacherMessage"> </label> <p>点击选择文件</p> </div>');
                $("#Popup").show();
            });
            $("#Popup .popup_contenthead span").off("click").click(function() {//点击隐藏

                $("#Popup").hide();
            });
            $("#Popup  .cancel").off("click").click(function() {//点击取消

                $("#Popup").hide();
            });

            $(document).off("change").on("change", "#Popup #teacherMessage", function() { //上传文件

                //$("#Popup .pop_main").html('<div class="pop_main_main"> <label class="form-group" for="teacherMessage"> 班级ID：<input type="text" name="classId" id="classId" value=0> 文件类型：<input type="text" name="type" id="type" value=2> <input type="file" name="file" id="teacherMessage"> </label> <p>点击选择文件</p> </div>');

                if($(this).val() != ""){
                    var type = $(this).val().substring($(this).val().lastIndexOf(".")).toLowerCase(); // 取文件格式后缀名
                    if(type != ".xls" && type != ".xlsx") {
                        $("#teacherMessage").val("");
                        self.alert1("请上传Excel文件，谢谢合作！","fail");

                        return false;
                    } else {


                        var filename = $(this).val().substring($(this).val().lastIndexOf("\\") + 1);
                        $("#Popup .pop_main h5").remove();
                        $("#Popup .pop_main").append("<h5>已选&ensp;:" + filename+ "</h5>");

                        return true;
                    }
                }else{
                    $("#teacherMessage").val("");
                    $("#Popup .pop_main h5").remove();
                }



            });
            $("#addOneChapter").submit(function(event) {//上传文件

                if($("#Popup h5").html() == null) {
                    self.alert1('请选择文件');
                    return false;
                }
                if($("#teacherMessage").val() != ""){
                    var formData = new FormData(this);
                    $.ajax({
                        url: "imStuExcelByClass",
                        type: 'post',
                        data: formData,
                        processData: false,
                        contentType: false,
                        beforeSend: function() {

                        },
                        success: function(responseStr) {
                            var responseStr=JSON.parse(responseStr);

                            if(responseStr.result =="success") {
                                self.alerty("上传成功");

                            } else {
                                // self.alert1(responseStr.errMsg);
                                if(responseStr.errMsg){
                                    self.alertI(responseStr.errMsg);
                                }else{
                                    self.alertI("上传失败");
                                }
                                $("#Popup .pop_main h5").remove();
                                $("#teacherMessage").val("");
                                $("#file").val("");
                            }

                        },
                        error: function(responseStr) {
                            var json = JSON.stringify({
                                "pageName": "error"
                            });
                            window.location.href = "skipPage?jsonStr=" + json;
                        }
                    });
                }

                //self.alert1("nono");


                $("#Popup").hide();
                return false;
            });
            $(document).on("change", "#department", function() { //院系联动专业

                if($("#department option:selected").attr("departmentId") == null) {

                    $("#major").html('<option value="1" >请选择</option>');
                } else {

                    var parameter = {
                        "departmentId": $("#department option:selected").attr("departmentId")
                    };

                    $.ajax({
                        type: "post",
                        url: "getProfessionListByDepmentId",
                        async: true,
                        data: {
                            "jsonStr": JSON.stringify(parameter)
                        },
                        success: function(data) {
                            //获取地点

                            var msgNew = JSON.parse(data);
                            var con = "";

                            for(key in msgNew.professionList) {
                                con += '<option value="1" professionId="' + msgNew.professionList[key].professionId + '">' + msgNew.professionList[key].professionName + '</option>';
                            }
                            $("#major").html(con);

                        },
                        error: function(data, status, xhr) {
                            var json = JSON.stringify({
                                "pageName": "error"
                            });
                            window.location.href = "skipPage?jsonStr=" + json;

                        }
                    });
                }
            });
        },
        addUser: function(message1, method1, after) { //编辑和增加教师
            // Alert1.contenthead = message1;
            Alert1.content = method1;
            Alert1.success = after;

            Alert1.init();
            $(".alert").attr("id", "addTeacher");

            $(".sex input").off("click").click(function() {

                $(this).next("label").addClass("checked").siblings("label").removeClass("checked");
            });
            $(".hover-btn").html("保存");
            $(".alert_contenthead").html("<div class=\"alert_contenthead\">"+message1+"<img class=\"alert_img\" src=\"pc/images/ico_alertDel.png\"></div>")
            $(".alert_img").off("click").click(function() {
                $(".alert,.abs_bg").hide();
            });
            // $("#teacherIntroduction").keydown(function(){
            // 	Alert1.success = function() {};
            // 	Alert1.hide = function() {};
            // });
            // $("#teacherIntroduction").keyup(function(){
            // Alert1.success = after;
            // Alert1.hide = function() {
            // 	Alert1.panel.style.display = "none";
            // 	Alert1.abs_bg.style.display = "none";
            // };
            // });
            Alert1.show();

        },
        postData: function(par_data, nowData, hunt) { //获得搜索及列表数据
            var self = this;
            var parameter = par_data;


            $.ajax({
                type: "post",
                url: "getOverMemberList",
                async: true,
                data: {
                    "jsonStr": JSON.stringify(parameter)
                },
                success: function(data, status, xhr) {
                    var new_data = JSON.parse(data);

                    if(hunt) {
                        self.tab_content = new_data;

                        self.tab_add();
                    } else {

                        self.data_content = new_data;
                        self.tab_content = new_data;

                        self.add();
                        self.tab_add();
                    }
                    // console.log(new_data.totalPage+"啊啊"+new_data.pageNow)
                    var sumpage = new_data.totalPage;
                    if(sumpage<1){sumpage=1;};
                    var nowpage = 1;
                    var pagenumber = 10;
                    var parame = parameter;
                    $(".tcdPageCode").createPage({
                        pageCount: sumpage, //总页数
                        current: nowpage, //当前页数
                        pageNumber: pagenumber, //每页显示数量
                        backFn: function(p) {

                            nowpage = p;

                            if(nowpage >= sumpage) {
                                nowpage = sumpage;
                            }
                            if(!parameter) {
                                parameter = {
                                    "pageNow": nowpage,
                                    "pageSize": 10
                                };

                            } else {
                                parameter.pageNow = nowpage;

                            }
                            $.ajax({
                                type: "post",
                                url: "getOverMemberList",
                                async: true,
                                data: {
                                    "jsonStr": JSON.stringify(parameter)
                                },
                                async: true,
                                success: function(msg) {
                                    //获取院系
                                    var msgNew = JSON.parse(msg);
                                    self.tab_content = msgNew;

                                    self.tab_add();
                                },
                                error: function(data, status, xhr) {
                                    var json = JSON.stringify({
                                        "pageName": "error"
                                    });
                                    window.location.href = "skipPage?jsonStr=" + json;

                                }
                            });
                        }
                    });
                },
                error: function(data, status, xhr) {
                    var json = JSON.stringify({
                        "pageName": "error"
                    });
                    window.location.href = "skipPage?jsonStr=" + json;

                }
            });
        },
        add: function() { //搜索追加
            var self = this;
            var data = self.data_content;
            for(key in data.departMentList) {
                $("#departNames").append("<option departmentId=" + data.departMentList[key].departmentId + ">" + data.departMentList[key].departmentName + "</option>");
            }

            $(".funBox .searchBtn").off("click").click(function() { //搜索点击

                var departmentId = $("#departNames option:selected").attr("departmentId");
                var keyW = $("#keyWord").val();
                var nowData = 1;
                if(verification.specialCode(keyW)!==true){
                    self.alert1("不能输入特殊字符(@/'\"#$%&^*)");
                    return;
                }

                var parameter = {
                    "userName": keyW,
                    "departmentId": departmentId,
                    "pageNow": 1,
                    "pageSize": 10,
                    "roleMark": 2,
                    "roleId":2,
                    "selecetRoleId":2
                };
                //遍历删除空元素
                var j=0;
                for(i in parameter){
                    if(j==0){j++;continue;}
                    if(parameter[i]==null||parameter[i]==""){
                        delete parameter[i];
                    }
                    if(!isNaN(parameter[i])){
                        parameter[i]=Number(parameter[i]);
                    }
                }



                self.postData(parameter, nowData, 1);
            });

        },
        tab_add: function() { //列表追加

            var self = this;
            var data = self.tab_content;
            var table = string1;

            //data.selectList={};

            var i = 0;
            for(key in data.memberList) {
                i++;
            }

            if(i > 0) {

                for(key in data.memberList) {

                    table += tabelModel(data);
                }

                $(".mainContent .tableBox").html(table);
            } else {
                var trImg = "<tr><td colspan='8'><img style='margin: 80px auto 20px;' src='pc/images/ico_noneData.png'><p style='font-size:26px;color:#8a8a8a;width:100%;text-align:center;'>暂无数据</p></td/tr>";
                $(".mainContent .tableBox").html(string1 + trImg);
            }

            //设置列表宽度(最大为9)
            var numMax = 0;
            $(".tableBox tr th").each(function() {
                var str = $(this).attr("class");
                var num = str.lastIndexOf("col-lg-") + 7;
                var num1 = parseFloat(str.substring(num, num + 1));
                numMax += num1;
            });

            $(".tableBox tr th").each(function() {
                var str = $(this).attr("class");
                var num = str.lastIndexOf("col-lg-") + 7;
                var num1 = parseFloat(str.substring(num, num + 1));

                $(this).css("width", num1 / numMax * 100 + "%");
            });
            self.allCheckEvent();
            $(".set").off("click").click(function() { //修改信息
                var stuorteaId=$(this).parents("tr").children("td").children(".oneCheck").attr("stuorteaId");
                var par = {
                    "pageNow":0,
                    "pageSize":10,
                    "param":2,
                    "roleId":2,
                    "selecetRoleId":2,
                    "stuorteaId": stuorteaId
                };
                var $_self = self;
                var sexThis = $(this).parents("tr").children(".sexName").html();

                $.ajax({
                    type: "post",
                    url: "getMemberDetailById",
                    async: true,
                    data: {
                        "jsonStr": JSON.stringify(par)
                    },

                    success: function(msg) {

                        var msgNew = JSON.parse(msg);

                        var method = setTeacher(msgNew, sexThis);
                        var $self = $_self;
                        var sub = function() {
                            console.log()
                            var stuorteaId = $("#workId").html();
                            /*var userName = $("#name" ).val();*/
                            var telephoneNum = $("#phone").val();

                            var userName = $("#teacherName").val();
                            var userContect = $("#teacherIntroduction").val();
                            var stuorteaId = $("#workId").html();
                            var n = /^[1-9]\d*$|^0$/;
                            if(verification.specialCode(userContect) !== true) {
                                $self.alert1("不能输入特殊字符(@/'\"#$%&^*)","fail");
                            }else if(verification.specialCode(userName) !== true) {
                                $self.alert1("不能输入特殊字符(@/'\"#$%&^*)","fail");
                            }else if(verification.specialCode(telephoneNum) !== true) {
                                $self.alert1("不能输入特殊字符(@/'\"#$%&^*)","fail");
                            }else if(userName == "") {
                                Alert2.content = "请输入正确姓名";
                                Alert2.success=function(){
                                    Alert1.show();
                                };
                                Alert2.init();
                                $(".alert").css("width", "640px");

                                Alert2.show();
                            }else {

                                if($(".sex .checked").html() == "男") {
                                    var userSex = 'm';
                                } else {
                                    var userSex = 'f';
                                }
                                var parameter = {
                                    "telephoneNum": telephoneNum,
                                    "userName": userName,
                                    "userSex": userSex,
                                    "stuorteaId": stuorteaId,
                                    "userContect": userContect

                                };

                                $.ajax({
                                    type: "post",
                                    url: "saveMemberMsg",
                                    async: true,
                                    data: {
                                        "jsonStr": JSON.stringify(parameter)
                                    },

                                    success: function(msg) {

                                        var msgNew = JSON.parse(msg);

                                        var self = $self;
                                        if(msgNew.result == "success") {
                                            self.alerty("提交成功");
                                            // window.location.reload(true);
                                        } else {
                                            //self.alert1("提交失败");
                                            if(msgNew.failMsg){
                                                self.alertA(msgNew.failMsg);
                                            }else{
                                                self.alertA("提交失败");
                                            }

                                        }

                                    },
                                    error: function(data, status, xhr) {
                                        var json = JSON.stringify({
                                            "pageName": "error"
                                        });
                                        window.location.href = "skipPage?jsonStr=" + json;

                                    }
                                });
                            }
                            $(".alert").removeAttr("id");
                        };
                        self.addUser("修改教师", method, sub);

                    },
                    error: function(data, status, xhr) {
                        var json = JSON.stringify({
                            "pageName": "error"
                        });
                        window.location.href = "skipPage?jsonStr=" + json;

                    }
                });
            });

            $(".initialization").off("click").click(function() { //重置密码
                var stuorteaId = $(this).attr("stuorteaId");
                var parameter = {
                    "stuorteaId": stuorteaId
                };
                $.ajax({
                    type: "post",
                    url: "resetPwd",
                    async: true,
                    data: {
                        "jsonStr": JSON.stringify(parameter)
                    },

                    success: function(msg) {

                        var msgNew = JSON.parse(msg);

                        if(msgNew.result == "success") {
                            self.alert1("初始化密码成功");

                        } else {
                            //self.alert1(msgNew.errorMsg);
                            if(msgNew.errorMsg){
                                self.alert1(msgNew.errorMsg);
                            }else{
                                self.alert1("初始化密码失败");
                            }

                        }

                    },
                    error: function(data, status, xhr) {
                        var json = JSON.stringify({
                            "pageName": "error"
                        });
                        window.location.href = "skipPage?jsonStr=" + json;

                    }
                });

            });
        },
        alert1: function(content1,state) { //confirm提示

            Alert2.contenthead = "提示";
            Alert2.content = content1;

            Alert2.success = function() {
                if(state=="fail"){
                    Alert1.show();

                }else{
                    // window.location.reload();
                    // Alert2.hide();
                    $(".alert").eq(0).remove();
                    $(".abs_bg").eq(1).remove();
                }
            };

            Alert2.init();
            Alert2.show();
        },
        alertI: function(content1,state) { //confirm提示

            Alert2.contenthead = "提示";
            Alert2.content = content1;

            Alert2.success = function() {
                if(state=="fail"){
                    Alert1.show();

                }else{
                    // window.location.reload();
                    // Alert2.hide();
                    $("#Popup").show();
                    $(".alert").eq(0).remove();
                    $(".abs_bg").eq(1).remove();
                }
            };

            Alert2.init();
            Alert2.show();
        },
        alertA: function(content1,state) { //confirm提示

            Alert2.contenthead = "提示";
            Alert2.content = content1;

            Alert2.success = function() {
                if(state=="fail"){
                    Alert1.show();

                }else{
                    // window.location.reload();
                    // Alert2.hide();
                    $(".alert").eq(0).show();
                    $(".abs_bg").eq(0).show();
                    $(".alert").eq(1).remove();
                    $(".abs_bg").eq(1).remove();
                }
            };

            Alert2.init();
            Alert2.show();
        },
        alerty: function(content1,state) { //confirm提示

            Alert2.contenthead = "提示";
            Alert2.content = content1;

            Alert2.success = function() {
                if(state=="fail"){
                    Alert1.show();

                }else{
                    window.location.reload(true);
                }
            };

            Alert2.init();
            Alert2.show();
        },
        confirm2: function(content1,method,methodErr) { //confirm提示

            confirm2.contenthead = "提示";
            confirm2.content = content1;

            confirm2.success = method;
            if(methodErr){
                confirm2.fail = methodErr;
            }
            confirm2.init();
            confirm2.show();
        },
        confirm3: function(content1,method,methodErr) { //confirm提示

            confirm3.contenthead = "提示";
            confirm3.content = content1;

            confirm3.success = method;
            if(methodErr){
                confirm3.fail = methodErr;
            }
            confirm3.init();
            confirm3.show();
        },
        allCheckEvent: function() {
            //全选
            allCheck.init("controlAll", "oneCheck");
        },
        delListEvent: function() { //批量删除
            var $_self = this;
            if($(".oneCheck[value=1]").length == 0) {
                Alert1.contenthead = "提示";
                Alert1.content = "请选择要删除的教师";
                Alert1.success = function() {};
                Alert1.init();
                Alert1.show();
            } else {

                confirm1.success = function() {
                    var list = [];
                    $(".box_1 tr td .oneCheck").each(function() {
                        if(parseInt($(this).val()) == 1) {
                            list.push($(this).attr("stuorteaId"));

                        }

                    });

                    var self = $_self;

                    var delPersonnel=function(marks){

                        var deleteDepartmentparameters = {
                            "list": list,
                            "marks": marks
                        };
                        $.ajax({//删除人员
                            type: "post",
                            url: "delMembers",
                            async: true,
                            data: {
                                "jsonStr": JSON.stringify(deleteDepartmentparameters),
                                "memType":1
                            },

                            success: function(msg) {

                                var msgNew = JSON.parse(msg);

                                if(msgNew.result == "success") {
                                    self.alerty("删除成功");
                                    // window.location.reload(true);
                                } else {
                                    //self.alert1(msgNew.resultMsg);
                                    if(msgNew.resultMsg){
                                        self.alerty(msgNew.resultMsg);
                                    }else{
                                        self.alert1("删除失败");
                                    }

                                }
                                $(".alert").removeClass("delPass");
                            },
                            error: function(data, status, xhr) {
                                var json = JSON.stringify({
                                    "pageName": "error"
                                });
                                window.location.href = "skipPage?jsonStr=" + json;

                            }
                        });
                    };
                    var delPass=function(){


                        var Unbundling=function(){delPersonnel(1);};
                        var delUnbundling=function(){delPersonnel(2);};
                        self.confirm3("",Unbundling,delUnbundling);
                        $(".alert").addClass("delPass");
                        $(".delPass .alert_img").remove();
                        $(".delPass .alert_confirm").html("解绑虚机");
                        $(".delPass .alert_close").html("删除虚机");
                    };
                    var isVmparameters = {
                        "list": list,
                        "type": 2
                    };
                    $.ajax({//判断是否存在虚拟机
                        type: "post",
                        url: "isVm",
                        async: true,
                        data: {
                            "jsonStr": JSON.stringify(isVmparameters),
                            "memType":1
                        },

                        success: function(msg) {

                            var msgNew = JSON.parse(msg);

                            if(msgNew.result == "success") {
                                if(msgNew.isVmtype==1){
                                    self.confirm2(msgNew.msg,delPass);
                                }else{
                                    delPersonnel(2);
                                }


                            } else {
                                if(msgNew.msg){
                                    self.alert1(msgNew.msg);
                                }else{
                                    self.alert1("删除失败");
                                }
                            }

                        },
                        error: function(data, status, xhr) {
                            var json = JSON.stringify({
                                "pageName": "error"
                            });
                            window.location.href = "skipPage?jsonStr=" + json;

                        }
                    });
                };
                var num = 0;
                $(".box_1 tr td .oneCheck").each(function() {
                    if(parseInt($(this).val()) == 1) {
                        num++;
                    }

                });
                if(num < 2) {
                    confirm1.content = "确定删除这个教师吗";
                } else {
                    confirm1.content = "确定删除这<a href='javascript:void(0)'>" + num + "</a>个教师吗";
                }

                confirm1.init();
                $(".alert_content a").css({
                    "margin": "2px",
                    "color": "#c82011",
                    "text-decoration": "underline"
                });
                confirm1.show();

            }
        },
        fileEvent: function() {//上传验证
            var self=this;
            $("#file").change(function() {
                var type = $(this).val().substring($(this).val().lastIndexOf(".")).toLowerCase(); // 取文件格式后缀名
                if(type != ".xls" && type != ".xlsx") {
                    $("#file").val("");
                    self.alert1("请上传Excel文件，谢谢合作！","fail");

                    return false;
                } else {
                    var filename = $(this).val().substring($(this).val().lastIndexOf("\\") + 1);
                    $fileName.html("已选:" + filename);
                    return true;
                }
            });
        }

    };
    index.init();

});